package com.jiaofamily.android.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.jiaofamily.android.ssq.BallData;

public class SsqDatabaseHelper extends SQLiteOpenHelper{
	private static final int DATABASE_VERSION = 1;
	
	public SsqDatabaseHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}
	
	public SsqDatabaseHelper(Context context, String name, int version) {
		this(context,name,null,version);
	}
	
	public SsqDatabaseHelper(Context context, String name) {
		this(context,name,DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		
		db.execSQL(BallData.SQL_COMMAND_CREATE_TABLE_HISTORY);
		db.execSQL(BallData.SQL_COMMAND_CREATE_TABLE_SELECTION);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		Log.w("SsqDatabaseHelper", "upgrading database from version "+oldVersion+" to"+ newVersion+", which will " +
				"destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " +BallData.TABLE_NAME_SELECTION);
		onCreate(db);
	}

	
}
